package com.fulu.game.bi.controller.play;

import com.fulu.game.bi.entity.bo.channel.GameOneClickListBO;
import com.fulu.game.bi.entity.bo.channel.GamePathListBO;
import com.fulu.game.bi.entity.bo.channel.GamePriceListBO;
import com.fulu.game.bi.entity.bo.channel.GameRoomStatListBO;
import com.fulu.game.bi.entity.dto.GameOneClickListDTO;
import com.fulu.game.bi.entity.dto.GamePathListDTO;
import com.fulu.game.bi.entity.dto.GamePriceListDTO;
import com.fulu.game.bi.entity.dto.GameRoomStatListDTO;
import com.fulu.game.bi.entity.vo.Result;
import com.fulu.game.bi.entity.vo.common.NameMsgVO;
import com.fulu.game.bi.redis.service.play.GamePlaySceneService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 游戏陪玩-陪玩场景
 */
@RestController
@RequestMapping("/api/play/scene")
@Slf4j
public class GamePlaySceneController {
    @Autowired
    private GamePlaySceneService gamePlaySceneService;

    /**
     * 派单厅-实时
     */
    @RequestMapping("/room-real-time")
    public Result roomRealTime() {
        return Result.success().data(gamePlaySceneService.roomRealTime());
    }

    /**
     * 派单厅-列表
     */
    @RequestMapping("/room-list")
    public Result roomList(GameRoomStatListDTO dto) {
        GameRoomStatListBO bo = new GameRoomStatListBO();
        BeanUtils.copyProperties(dto, bo);
        return Result.success().data(gamePlaySceneService.list(bo));
    }

    /**
     * 派单厅-导出
     */
    @RequestMapping("/room-export")
    public void roomExport(GameRoomStatListDTO dto) {
        GameRoomStatListBO bo = new GameRoomStatListBO();
        BeanUtils.copyProperties(dto, bo);
        gamePlaySceneService.export(bo);
    }
    /**
     * 派单厅-折线图
     */
    @RequestMapping("/room-line-chart")
    public Result roomLineChart() {
        Map<String, String> cacheMap = new LinkedHashMap<>();
        cacheMap.put("曝光人数", "exposureUserNum");
        cacheMap.put("曝光次数", "exposureNum");
        cacheMap.put("进厅人数", "enterRoomUserNum");
        cacheMap.put("进厅次数", "enterRoomNum");
        cacheMap.put("CTR", "ctr");
        cacheMap.put("进厅陪玩师", "enterRoomPlayeeNum");
        cacheMap.put("试音人数", "tryVioceUserNum");
        cacheMap.put("试音次数", "tryVioceNum");
        cacheMap.put("派单次数", "dispathcNum");
        cacheMap.put("派单成功次数", "dispathcSuccessNum");
        cacheMap.put("重新派单次数", "retryDispathcNum");
        cacheMap.put("弃单次数", "dropOrderNum");
        cacheMap.put("弃单率", "dropOrderNumRatio");
        cacheMap.put("消费总额", "consumeMoneyAll");
        cacheMap.put("下单人数", "orderUserNum");
        cacheMap.put("下单次数", "orderNum");
        cacheMap.put("CVR", "cvr");
        cacheMap.put("订单消费金额", "orderConsumeMoneyAll");
        cacheMap.put("钻石消费人数", "virtualMoneyUserNum");
        cacheMap.put("钻石消费次数", "virtualMoneyNum");
        cacheMap.put("钻石消费金额", "virtualMoneyAll");
        cacheMap.put("礼物魅力值", "charmMoneyAll");
        cacheMap.put("退款人数", "refundUserNum");
        cacheMap.put("退款次数", "refundNum");
        cacheMap.put("退款率", "refundNumRatio");
        cacheMap.put("平均派单时长", "dispathcTimeAvg");

        List<NameMsgVO> list = cacheMap.entrySet().stream()
                .map(entry -> {
                    NameMsgVO idNameVO = new NameMsgVO();
                    idNameVO.setName(entry.getValue());
                    idNameVO.setMsg(entry.getKey());
                    if (entry.getValue().toLowerCase(Locale.getDefault()).contains("ctr") || entry.getValue().toLowerCase(Locale.getDefault()).contains("cvr")) {
                        idNameVO.setType("percent");
                    }
                    return idNameVO;
                })
                .collect(Collectors.toList());

        return Result.success().data(list).msg("获取成功");
    }


    /**
     * 游戏陪玩-陪玩场景-路径列表
     */
    @RequestMapping("/path-list")
    public Result pathList(GamePathListDTO dto) {
        GamePathListBO bo = new GamePathListBO();
        BeanUtils.copyProperties(dto, bo);
        return Result.success().data(gamePlaySceneService.pathList(bo));
    }

    /**
     * 游戏陪玩-陪玩场景-路径导出
     */
    @RequestMapping("/path-export")
    public void pathExport(GamePathListDTO dto) {
        GamePathListBO bo = new GamePathListBO();
        BeanUtils.copyProperties(dto, bo);
        gamePlaySceneService.pathExport(bo);
    }


    /**
     * 游戏陪玩-陪玩场景-一键下单-实时
     */
    @RequestMapping("/click-realtime")
    public Result clickRealtime() {
        return Result.success().data(gamePlaySceneService.clickRealtime());
    }

    /**
     * 游戏陪玩-陪玩场景-一键下单-列表
     */
    @RequestMapping("/click-list")
    public Result clickList(GameOneClickListDTO dto) {
        GameOneClickListBO bo = new GameOneClickListBO();
        BeanUtils.copyProperties(dto, bo);
        return Result.success().data(gamePlaySceneService.clickList(bo));
    }

    /**
     * 游戏陪玩-陪玩场景-一键下单-导出
     */
    @RequestMapping("/click-export")
    public void clickExport(GameOneClickListDTO dto) {
        GameOneClickListBO bo = new GameOneClickListBO();
        BeanUtils.copyProperties(dto, bo);
        gamePlaySceneService.clickExport(bo);
    }

    /**
     * 游戏陪玩-陪玩场景-一键下单-折线图
     */
    @RequestMapping("/click-line-chart")
    public Result clickLineChart() {
        Map<String, String> cacheMap = new LinkedHashMap<>();
        cacheMap.put("进入人数", "enterUserNum");
        cacheMap.put("进入次数", "enterNum");
        cacheMap.put("发单人数", "sendOrderUserNum");
        cacheMap.put("发单次数", "sendOrderNum");
        cacheMap.put("下单人数", "orderUserNum");
        cacheMap.put("下单新用户数", "orderNewUserNum");
        cacheMap.put("下单次数", "orderNum");
        cacheMap.put("下单金额", "orderMoneyAll");
        cacheMap.put("抢单人数", "robOrderUserNum");
        cacheMap.put("系统匹配下单人数", "systemMatchUserNum");
        cacheMap.put("系统匹配下单次数", "systemMatchNum");
        cacheMap.put("人工抢单下单人数", "manualRobOrderUserNum");
        cacheMap.put("人工抢单下单次数", "manualRobOrderNum");
        cacheMap.put("超时人数", "timeoutUserNum");
        cacheMap.put("超时次数", "timeoutNum");
        cacheMap.put("取消人数", "cancelUserNum");
        cacheMap.put("取消次数", "cancelNum");
        cacheMap.put("退款人数", "refundUserNum");
        cacheMap.put("退款次数", "refundNum");
        cacheMap.put("平均匹配时长", "matchTimeAll");
        List<NameMsgVO> list = cacheMap.entrySet().stream()
                .map(entry -> {
                    NameMsgVO idNameVO = new NameMsgVO();
                    idNameVO.setName(entry.getValue());
                    idNameVO.setMsg(entry.getKey());
                    return idNameVO;
                })
                .collect(Collectors.toList());
        return Result.success().data(list).msg("获取成功");
    }


    /**
     * 游戏陪玩-陪玩场景-新客价-实时
     */
    @RequestMapping("/price-realtime")
    public Result priceRealtime() {
        return Result.success().data(gamePlaySceneService.priceRealtime());
    }

    /**
     * 游戏陪玩-陪玩场景-新客价-列表
     */
    @RequestMapping("/price-list")
    public Result priceList(GamePriceListDTO dto) {
        GamePriceListBO bo = new GamePriceListBO();
        BeanUtils.copyProperties(dto, bo);
        return Result.success().data(gamePlaySceneService.priceList(bo));
    }

    /**
     * 游戏陪玩-陪玩场景-新客价-导出
     */
    @RequestMapping("/price-export")
    public void priceExport(GamePriceListDTO dto) {
        GamePriceListBO bo = new GamePriceListBO();
        BeanUtils.copyProperties(dto, bo);
        gamePlaySceneService.priceExport(bo);
    }

    /**
     * 游戏陪玩-陪玩场景-新客价-折线图
     */
    @RequestMapping("/price-line-chart")
    public Result priceLineChart() {
        Map<String, String> cacheMap = new LinkedHashMap<>();
        cacheMap.put("进入人数", "enterUserNum");
        cacheMap.put("进入次数", "enterNum");
        cacheMap.put("开启人数", "openUserNum");
        cacheMap.put("接单人数", "orderUserNum");
        cacheMap.put("接单次数", "orderNum");
        cacheMap.put("接单金额", "robOrderMoneyAll");
        List<NameMsgVO> list = cacheMap.entrySet().stream()
                .map(entry -> {
                    NameMsgVO idNameVO = new NameMsgVO();
                    idNameVO.setName(entry.getValue());
                    idNameVO.setMsg(entry.getKey());
                    return idNameVO;
                })
                .collect(Collectors.toList());
        return Result.success().data(list).msg("获取成功");
    }
}
